Algorithms

What is an algorithm

Example-1

List all even numbers from 1 to 1000 2, 4, 6, 8, 10, 12....998, 1000

          
         assign 0 to x.      (x = 0)  
         for number i = 1 to 500   (i = 500)  
          increase x by 2        	(x = 1000)  
          Display x 
          next i 
     
     

Example-2

Find the maximum number in the following list: 1, 3, 5, 6, 2, 8, 9, 10, 11, 2, 4

          
         maxNumber = The first number
         for every number in the list
	         if the number is greater than maxNumber 
		        assign number to the maxNumber
         next number
         print maxNumber
      
     

Example-3

Find all even numbers in the following list: 1, 3, 5, 6, 2, 8, 9, 10, 11, 2, 4

           
         for every number in the list
             divide the number by 2 
             get the remainder of the division 
             if the remainder = 0
	            the number is even, print it 
             else
	            the number is odd, do nothing
         next number
     
     

Algorithm in computer terms

Example-4

Solution

         from 1 to the number of boxes 
	          draw a box
	          change drawing angle by 5 degrees 
         next box 
     

For more details, please contact me here.
Date of last modification: 2021